﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using CeA.Reports.Atendimento.Web.WebControls;
using Qtech.Reports.Atendimento.Services;
using CeA.Reports.Atendimento.DataAccess.DTO;
using CeA.Reports.Atendimento.DataAccess.Criteria;
using CeA.Reports.Atendimento.DataAccess.Helpers;
using libFusion.data;


namespace CeA.Reports.Atendimento.Web.site {
    public partial class relatorioservico : System.Web.UI.Page {

        //utilizado para regioes e totalizador
        DataTable m_dtFooter = new DataTable();
        DataTable m_dtLoja = new DataTable();

        int indexFooter = 0;

        protected void Page_Init(object sender, EventArgs e)                        {
            filtro.Pesquisar += new FiltroServico.FiltroServicoEventHandler(filtro_Pesquisar);
            btnExportarExcel.Click += new EventHandler(btnExportarExcel_Click);
        }


        protected void Page_Load(object sender, EventArgs e)                        {

        }


        protected void filtro_Pesquisar(object sender, FiltroServicoEventArgs e)    {
            carregarRelatorio(e);
            ViewState.Add("filtro", e);
            btnExportarExcel.Visible = true;//e.ExportaRelatorio;
            pnlImprimir.Visible = true;
        }


        protected void btnExportarExcel_Click(object sender, EventArgs e)           {
            //limpo a resposta do HTTP
            Response.Clear();
            //adiciono o cabeçalho que faz o .Net entender que se trata de um xls
            Response.AddHeader("content-disposition", "attachment;filename=servicos_report.xls");
            //zero o charset
            Response.Charset = "";
            //desabilito o cache do browser
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            //Seto o content type para xls
            Response.ContentType = "application/vnd.xls";
            //Crio um String Writer
            System.IO.StringWriter sWr = new System.IO.StringWriter();
            //Transformo em HTML String Writer
            System.Web.UI.HtmlTextWriter hWr = new HtmlTextWriter(sWr);
            //Mando o datagrid (que deve ser criado antes de renderizar o HtmlTextWriter criado...
            carregarRelatorio(ViewState["filtro"] as FiltroServicoEventArgs);
            resultTable.RenderControl(hWr);
            //mando escrever na tela. Com todos os cabeçalhos setados, é aberto para salvar o XML
            Response.Write(sWr.ToString());
            //Fecho a resposta.
            Response.End();
        }


        private void carregarRelatorio(FiltroServicoEventArgs e)                    {
            RelatorioServicoFilter filter = new RelatorioServicoFilter();

            filter.RegiaoList = e.Regiao;
            filter.RfsList = e.Rfs;
            filter.LojaList = e.Lojas;
            filter.ServicoList = e.Servicos;
            filter.DataIncidencia = new DateTime(e.Ano, e.Mes, 1);

            RelatorioServicoDTO dto = CadastroFacade.FindServicoReportBy(filter);
            DataTable dt = dto.TableRelatorio;
            m_dtLoja = dt;

            RelatorioServicoDTO dtoRFS = CadastroFacade.FindServicoReportByRFS(filter);
            DataTable dtRFS = dtoRFS.TableRelatorio;

            RelatorioServicoDTO dtoBrasil = CadastroFacade.FindServicoReportByBrasil(filter);
            DataTable dtBrasil = dtoBrasil.TableRelatorio;


            buildTableGroups(dt);
            buildTableHeader(dt);
            buildTableBody(dt);

            buildTableFooterBrasil(dtBrasil);
            buildTableFooterRFS(dtRFS);

            report.Visible = true;

            //if (e.GeraGrafico) {
                gerarGrafico(e.Ano, e.Mes);
            //}
        }


        private void buildTableGroups(DataTable dt)                                 {
            TableRow row = new TableRow();
            row.Style.Value = "height:28px; background-color:#CCCDFF;";
            row.CssClass = "th";

            // Primeira Coluna da Tabela
            row.Cells.Add(new TableCell());
            row.Cells[0].Style.Value = "width:50px";
            row.Cells[0].Text = "&nbsp;";

            for (int idx = 2; idx < dt.Columns.Count; idx++) {
                if ((idx - 3) % 3 == 0 && idx < dt.Columns.Count - 1) {
                    TableCell cell = new TableCell();
                    cell.Text = CadastroFacade.GetServico(Convert.ToInt32(dt.Columns[idx].ColumnName.Substring(0, 4))).Nome;
                    cell.VerticalAlign = VerticalAlign.Top;                    
                    cell.Style.Value = "font-size:.9em; border-left: 1px solid #222; ";
                    cell.ColumnSpan = 3;
                    row.Cells.Add(cell);
                }
                if (idx == dt.Columns.Count - 1) {
                    TableCell cell = new TableCell();
                    cell.Text = dt.Columns[idx].ColumnName.Substring(5);
                    cell.VerticalAlign = VerticalAlign.Top;
                    cell.Style.Value = "font-size:.9em; border-left: 1px solid #222;";
                    row.Cells.Add(cell);
                }
            }

            resultTable.Rows.AddAt(0, row);
        }


        private void buildTableHeader(DataTable dataTable)                          {
            TableRow row = new TableRow();
            row.Style.Value = "height:20px; background-color:#CCCDFF;";

            // Primeira Coluna da Tabela
            row.Cells.Add(new TableCell());
            row.Cells[0].Style.Value = "width:50px";
            row.Cells[0].Text = "Loja";

            int cellPos = 0;

            for (int idx = 3; idx < dataTable.Columns.Count; idx++) {
                TableCell cell = new TableCell();

                if (cellPos % 3 == 0) {
                    cell.CssClass = "th-lb lb-0";
                }
                else {
                    cell.CssClass = "th-lb";
                }
                if(dataTable.Columns[idx].ColumnName.Substring(5) == "QT"){
                    cell.Text = "#";
                }else{
                    cell.Text = dataTable.Columns[idx].ColumnName.Substring(5);
                }


                cellPos++;

                row.Cells.Add(cell);
            }
            resultTable.Rows.Add(row);
        }


        private void buildTableBody(DataTable dataTable)                            {

            TableRow row = new TableRow();
            TableRow rowRG = new TableRow();

            DataRow drData = null;
            DataRow drDataTotal = null;

            String auxRegiao = null;
            String auxRegiaoProx = null;
            Int32 auxTMP = 0;
            Decimal auxPerc = 0;

            for (int colNum = 2; colNum < dataTable.Columns.Count; colNum++) {
                m_dtFooter.Columns.Add(dataTable.Columns[colNum].ColumnName);
            }
            drData = m_dtFooter.NewRow();
            drData[0] = "";
            drDataTotal = m_dtFooter.NewRow();
            drDataTotal[0] = "Total";

            for (int colNum = 1; colNum < m_dtFooter.Columns.Count; colNum++) {
                drData[colNum] = 0;
                drDataTotal[colNum] = 0;
            }


            for (int rowNum = 0; rowNum < dataTable.Rows.Count; rowNum++) {
                if (rowNum == 0) {
                    auxRegiao = Convert.ToString(dataTable.Rows[rowNum][1]);
                }
                row.Style.Value = "height:20px;";

                for (int colNum = 2; colNum < dataTable.Columns.Count; colNum++) {
                    TableCell cell = new TableCell();

                    if ((colNum - 2) % 3 == 1) {
                        cell.CssClass = "th-lb lb-0";
                    }
                    else {
                        cell.CssClass = "th-lb";

                    }
                    switch (dataTable.Columns[colNum].ColumnName.Substring(5).ToUpper()) {
                        case "QT":
                            cell.Text = "<div width='30px' class='block'>" + Convert.ToString(dataTable.Rows[rowNum][colNum]) + "</div>";
                            if (dataTable.Rows[rowNum][colNum] != DBNull.Value) {
                                drData[colNum - 2] = Convert.ToInt32(drData[colNum - 2]) + Convert.ToInt32(dataTable.Rows[rowNum][colNum]);
                                drDataTotal[colNum - 2] = Convert.ToInt32(drDataTotal[colNum - 2]) + Convert.ToInt32(dataTable.Rows[rowNum][colNum]);
                            }
                            break;

                        case "TMA":
                            cell.Text = "<div width='30px' class='block'>" + ConvertHelper.SecondToHour(Convert.ToInt32(dataTable.Rows[rowNum][colNum])).Substring(3) + "</div>";
                 
                            if (dataTable.Rows[rowNum][colNum] != DBNull.Value) {
                                drData[colNum - 2] = Convert.ToInt32(drData[colNum - 2]) + (Convert.ToInt32(dataTable.Rows[rowNum][colNum - 1]) * Convert.ToInt32(dataTable.Rows[rowNum][colNum]));
                                drDataTotal[colNum - 2] = Convert.ToInt32(drDataTotal[colNum - 2]) + (Convert.ToInt32(dataTable.Rows[rowNum][colNum - 1]) * Convert.ToInt32(dataTable.Rows[rowNum][colNum]));
                            }

                            break;

                        case "%":
                            cell.Text = "<div width='30px' class='block'>" + Convert.ToString(dataTable.Rows[rowNum][colNum]) + "</div>";
                            drData[colNum - 2] = 0;
                            drDataTotal[colNum - 2] = 0;
                            break;

                        case "TOTAL":
                            cell.Text = "<div width='30px' class='block'>" + Convert.ToString(dataTable.Rows[rowNum][colNum]) + "</div>";
                            if (dataTable.Rows[rowNum][colNum] != DBNull.Value) {
                                drData[colNum - 2] = Convert.ToInt32(drData[colNum - 2]) + Convert.ToInt32(dataTable.Rows[rowNum][colNum]);
                                drDataTotal[colNum - 2] = Convert.ToInt32(drDataTotal[colNum - 2]) + Convert.ToInt32(dataTable.Rows[rowNum][colNum]);
                            }
                            break;

                        default:
                            cell.Text = "<div width='30px' class='block'>" + Convert.ToString(dataTable.Rows[rowNum][colNum]) + "</div>";
                            break;

                    }

                    row.Cells.Add(cell);
                }

                if (rowNum % 2 == 0)
                    row.CssClass = "cor-2";
                else
                    row.CssClass = "cor-1";
                resultTable.Rows.Add(row);
                row = new TableRow();

                if (rowNum + 1 < dataTable.Rows.Count) {
                    auxRegiaoProx = Convert.ToString(dataTable.Rows[rowNum + 1][1]);
                }

                //verifica se é uma nova região
                if (auxRegiao != auxRegiaoProx || rowNum == dataTable.Rows.Count - 1) {
                    TableCell cellRG = new TableCell();
                    rowRG.Style.Value = "height:20px; background-color: rgb(153,204,255);";

                    cellRG.Text = "<div width='30px' class='block'>" + auxRegiao + "</div>";
                    rowRG.Cells.Add(cellRG);
                    drData[0] = auxRegiao;

                    for (int colNumRG = 1; colNumRG < m_dtFooter.Columns.Count; colNumRG++) {
                        cellRG = new TableCell();
                        if ((colNumRG) % 3 == 1) {
                            cellRG.CssClass = "th-lb lb-0";
                        }
                        else {
                            cellRG.CssClass = "th-lb";
                        }

                        switch (m_dtFooter.Columns[colNumRG].ColumnName.Substring(5).ToUpper()) {
                            case "QT":
                                cellRG.Text = "<div width='30px' class='block'>" + drData[colNumRG].ToString() + "</div>";
                                break;
                            case "TMA":
                                auxTMP = 0;
                                if (Convert.ToInt32(drData[(colNumRG - 1)]) > 0)
                                    auxTMP = Convert.ToInt32(drData[colNumRG]) / Convert.ToInt32(drData[(colNumRG - 1)]);
                                cellRG.Text = "<div width='30px' class='block'>" + ConvertHelper.SecondToHour(auxTMP).Substring(3) + "</div>";
                                drData[colNumRG] = 0;
                                break;
                            case "%":
                                auxPerc = (Convert.ToDecimal(drData[colNumRG - 2]) * 100) / Convert.ToDecimal(drData[(m_dtFooter.Columns.Count - 1)]);
                                cellRG.Text = "<div width='30px' class='block'>" + Math.Round(auxPerc, 2).ToString() + "</div>";
                                drData[colNumRG] = 0;
                                drData[colNumRG - 2] = 0;
                                break;
                            case "TOTAL":
                                cellRG.Text = "<div width='30px' class='block'>" + drData[colNumRG].ToString() + "</div>";
                                drData[colNumRG] = 0;
                                break;
                            default:
                                //cell.Text = "<div width='30px' class='block'>" + Convert.ToString(dataTable.Rows[rowNum][colNum]) + "</div>";
                                break;

                        }
                        rowRG.Cells.Add(cellRG);
                    }
                    resultTable.Rows.Add(rowRG);

                    //linha em branco da divisao dos totalizadores de regioes
                    rowRG = new TableRow();
                    rowRG.Style.Value = "height:15px; background-color: rgb(255,255,255);";
                    cellRG = new TableCell();
                    cellRG.Style.Value = "colspan: " + (m_dtFooter.Columns.Count - 1) + ";";
                    rowRG.Cells.Add(cellRG);
                    resultTable.Rows.Add(rowRG);

                    rowRG = new TableRow();
                    auxRegiao = auxRegiaoProx;


                    //inicio do ultimo registro colocar o totalizador
                    if (rowNum == dataTable.Rows.Count - 1) {
                        cellRG = new TableCell();
                        rowRG.Style.Value = "height:20px; background-color: rgb(255,155,155);";

                        cellRG.Text = "<div width='30px' class='block'>Total</div>";
                        rowRG.Cells.Add(cellRG);
                        drDataTotal[0] = "Total";

                        for (int colNumRG = 1; colNumRG < m_dtFooter.Columns.Count; colNumRG++) {
                            cellRG = new TableCell();
                            if ((colNumRG) % 3 == 1) {
                                cellRG.CssClass = "th-lb lb-0";
                            }
                            else {
                                cellRG.CssClass = "th-lb";
                            }

                            switch (m_dtFooter.Columns[colNumRG].ColumnName.Substring(5).ToUpper()) {
                                case "QT":
                                    cellRG.Text = "<div width='30px' class='block'>" + drDataTotal[colNumRG].ToString() + "</div>";
                                    break;
                                case "TMA":
                                    auxTMP = 0;
                                    if (Convert.ToInt32(drDataTotal[(colNumRG - 1)]) > 0)
                                    {
                                        auxTMP = Convert.ToInt32(drDataTotal[colNumRG]) / Convert.ToInt32(drDataTotal[(colNumRG - 1)]);
                                        drDataTotal[colNumRG] = auxTMP;
                                    }
                                    cellRG.Text = "<div width='30px' class='block'>" + ConvertHelper.SecondToHour(auxTMP).Substring(3) + "</div>";
                                    break;
                                case "%":
                                    auxPerc = (Convert.ToDecimal(drDataTotal[colNumRG - 2]) * 100) / Convert.ToDecimal(drDataTotal[(m_dtFooter.Columns.Count - 1)]);
                                    cellRG.Text = "<div width='30px' class='block'>" + Math.Round(auxPerc, 2).ToString() + "</div>";
                                    break;
                                case "TOTAL":
                                    cellRG.Text = "<div width='30px' class='block'>" + drDataTotal[colNumRG].ToString() + "</div>";
                                    break;
                                default:
                                    //cell.Text = "<div width='30px' class='block'>" + Convert.ToString(dataTable.Rows[rowNum][colNum]) + "</div>";
                                    break;

                            }
                            rowRG.Cells.Add(cellRG);
                        }
                        resultTable.Rows.Add(rowRG);

                        //linha em branco da divisao dos totalizadores de regioes
                        rowRG = new TableRow();
                        rowRG.Style.Value = "height:15px; background-color: rgb(255,255,255);";
                        cellRG = new TableCell();
                        cellRG.Style.Value = "colspan: " + (m_dtFooter.Columns.Count - 1) + ";";
                        rowRG.Cells.Add(cellRG);
                        resultTable.Rows.Add(rowRG);
                    }//fim do ultimo registro colocar o totalizador

                }
            }
            m_dtFooter.Rows.Add(drDataTotal);
            indexFooter += 1;
        }


        private void buildTableFooterRFS(DataTable dataTable)                       {
            TableRow row = new TableRow();
            for (int rowNum = 0; rowNum < dataTable.Rows.Count; rowNum++) {

                row.Style.Value = "height:20px; background-color:#CCCDF" + rowNum + ";";

                for (int colNum = 0; colNum < dataTable.Columns.Count; colNum++) {
                    TableCell cell = new TableCell();

                    if ((colNum) % 3 == 1) {
                        cell.CssClass = "th-lb lb-0";
                    }
                    else {
                        cell.CssClass = "th-lb";

                    }

                    if (dataTable.Columns[colNum].ColumnName.Substring(5).ToUpper() == "TMA") {
                        cell.Text = "<div width='30px' class='block'>" + ConvertHelper.SecondToHour(Convert.ToInt32(dataTable.Rows[rowNum][colNum])).Substring(3) + "</div>";
                    }
                    else {
                        cell.Text = "<div width='30px' class='block'>" + Convert.ToString(dataTable.Rows[rowNum][colNum]) + "</div>";
                    }

                    row.Cells.Add(cell);
                }

                if (rowNum % 2 == 0)
                    row.CssClass = "cor-2";
                else
                    row.CssClass = "cor-1";

                resultTable.Rows.Add(row);

                row = new TableRow();
            }
        }


        private void buildTableFooterBrasil(DataTable dt)                           {
            TableRow row = new TableRow();
            row.Style.Value = "height:20px; background-color:#CCCDFF;";
            row.CssClass = "tf";

            for (int rowNum = 0; rowNum < dt.Rows.Count; rowNum++) {
                for (int colNum = 0; colNum < dt.Columns.Count; colNum++) {
                    TableCell cell = new TableCell();

                    if ((colNum) % 3 == 1)
                    {
                        cell.CssClass = "th-lb lb-0";
                    }
                    else
                    {
                        cell.CssClass = "th-lb";
                    }

                    if (dt.Columns[colNum].ColumnName.Substring(5).ToUpper() == "TMA") {
                        if (dt.Rows[rowNum][colNum] != DBNull.Value)
                            cell.Text = ConvertHelper.SecondToHour(Convert.ToInt32(dt.Rows[rowNum][colNum])).Substring(3);
                    }
                    else {
                        if (dt.Rows[rowNum][colNum] != DBNull.Value)
                            cell.Text = Convert.ToString(dt.Rows[rowNum][colNum]);
                    }

                    cell.VerticalAlign = VerticalAlign.Top;
                    row.Cells.Add(cell);
                }

            }

            resultTable.Rows.Add(row);
        }


        private void gerarGrafico(int ano, int mes)                                 {
            graph1Container.Visible = true;
            graph2Container.Visible = true;
            //graph3Container.Visible = true;
            
            gerarGraficoServico(ano, mes);
            gerarGraficoAtendimento(ano, mes);
            //gerarGraficoLoja(ano, mes);
        }


        private void gerarGraficoServico(int ano, int mes)                          {
            FusionMSColumn3DLineDYChart graph = new FusionMSColumn3DLineDYChart();
            graph.ChartPath = "/charts";
            graph.Caption = "QUANTIDADE DE CÓDIGOS DE SERVIÇO";
            graph.SubCaption = string.Format("{0} de {1}", extractLiteralMes(mes), ano);
            graph.PYAxisName = "Quantidade";
            graph.XAxisName = "Serviço";
            graph.RotateValues = true;
          
            
            graph.PosicaoInicioEixoY = 2;
            graph.NumberScaleValue = string.Empty;
            graph.NumberScaleUnit = string.Empty;
            graph.FormatNumberScale = false;
            graph.FormatNumber = false;
            graph.LabelDisplay = "ROTATE";
            graph.SlantLabels = true;

            graph.SYAxisName = string.Empty;
            graph.ShowSecondaryLimits = false;
            graph.ShowYValues = false;
            graph.SFormatNumber = false;
                                    
            
            DataTable dtGraph = new DataTable("GRAPH1");
            dtGraph.Columns.Add("Nome", typeof(string));
            dtGraph.Columns.Add("Quantidade", typeof(string));
            

            foreach (DataColumn col in m_dtFooter.Columns) {
                if (col.ColumnName.EndsWith("QT")) {
                    DataRow row = dtGraph.NewRow();
                    row["Nome"] = extractNomeServico(col);
                    row["Quantidade"] = Convert.ToString(m_dtFooter.Rows[0][col]);
                    dtGraph.Rows.Add(row);
                }
            }

            graph1Container.InnerHtml = graph.CreateSetElement(dtGraph,  "MSColumn3D.swf", graph1Container.ClientID, 750, 500);
        }


        private void gerarGraficoAtendimento(int ano, int mes)                      {
            FusionMSColumn3DLineDYChart graph = new FusionMSColumn3DLineDYChart();
            graph.ChartPath = "/charts";
            graph.Caption = "TEMPO DE ATENDIMENTO POR CÓDIGO DE SERVIÇO";
            graph.SubCaption = string.Format("{0} de {1}", extractLiteralMes(mes), ano);
            graph.PYAxisName = "Tempo";
            graph.XAxisName = "Serviço";
            graph.RotateValues = true;
            graph.PosicaoInicioEixoY = 2;
                

            graph.NumberScaleValue = "60,60,24,7";
            graph.NumberScaleUnit = "min,hr,day,wk";
            graph.DefaultNumberScale = "s";
            graph.SFormatNumber = true;
            graph.FormatNumber = true;

            graph.FormatNumberScale = true;
            graph.FormatNumber = true;
            graph.SYAxisName = string.Empty;
            graph.ShowSecondaryLimits = false;

            graph.ShowSecondaryLimits = false;
            graph.LabelDisplay = "ROTATE";
            graph.SlantLabels = true;
            graph.ShowYValues = false;
            
            
            
                        

            DataTable dtGraph = new DataTable("GRAPH2");
            dtGraph.Columns.Add("Nome", typeof(string));
            dtGraph.Columns.Add("Quantidade", typeof(int));

            foreach (DataColumn col in m_dtFooter.Columns)
            {
                if (col.ColumnName.EndsWith("TMA"))
                {
                    DataRow row = dtGraph.NewRow();
                    row["Nome"] = extractNomeServico(col);
                    row["Quantidade"] = Convert.ToInt32(m_dtFooter.Rows[0][col]);
                    dtGraph.Rows.Add(row);
                }
            }

            graph2Container.InnerHtml = graph.CreateSetElement(dtGraph, "MSColumn3D.swf", graph2Container.ClientID, 750, 500);
        }


        //private void gerarGraficoLoja(int ano, int mes)                             {
        //    FusionMSColumn3DLineDYChart graph = new FusionMSColumn3DLineDYChart();
        //    graph.ChartPath = "/charts";
        //    graph.Caption = "QUANTIDADE DE CODIGO DE SERVIÇO POR LOJA";
        //    graph.SubCaption = string.Format("{0} de {1}", extractLiteralMes(mes), ano);
        //    graph.PYAxisName = "Quantidade";
        //    graph.XAxisName = "Serviço";
        //    graph.RotateValues = false;
        //    graph.PosicaoInicioEixoY = 2;
        //    graph.NumberScaleValue = string.Empty;
        //    graph.NumberScaleUnit = string.Empty;
        //    graph.FormatNumberScale = false;
        //    graph.FormatNumber = false;
        //    graph.SYAxisName = string.Empty;

        //    graph.ShowSecondaryLimits = false;
        //    graph.LabelDisplay = "Rotate";
        //    graph.SlantLabels = false;
        //    graph.ShowYValues = false;
        //    graph.SFormatNumberScale = false;
            

        //    DataTable dtGraph = new DataTable("GRAPH3");
        //    dtGraph.Columns.Add("Nome", typeof(string));
        //    dtGraph.Columns.Add("Quantidade", typeof(string));

        //    foreach (DataRow lojaRow in m_dtLoja.Rows) {
        //        DataRow row = dtGraph.NewRow();
        //        row["Nome"] = Convert.ToString(lojaRow["LOJA_SIGLA"]);
        //        row["Quantidade"] = Convert.ToString(lojaRow["XXXX_TOTAL"]);
        //        dtGraph.Rows.Add(row);
        //    }

        //    graph3Container.InnerHtml = graph.CreateSetElement(dtGraph, "MSColumn3D.swf", graph3Container.ClientID, 908, 606);
        //}


        private string extractNomeServico(DataColumn dataColumn)                    {
            string name = string.Empty;

            switch (dataColumn.ColumnName.Substring(5).ToUpper()) {
                case "QT":
                    name = CadastroFacade.GetServico(Convert.ToInt32(dataColumn.ColumnName.Substring(0, 4))).Nome;
                    break;
                case "TMA":
                    name = CadastroFacade.GetServico(Convert.ToInt32(dataColumn.ColumnName.Substring(0, 4))).Nome;
                    break;
                case "%":
                    name = CadastroFacade.GetServico(Convert.ToInt32(dataColumn.ColumnName.Substring(0, 4))).Nome;
                    break;
                case "TOTAL":
                    name = CadastroFacade.GetServico(Convert.ToInt32(dataColumn.ColumnName.Substring(0, 4))).Nome;
                    break;
                default:
                    break;
            }

            return name;
        }


        private string extractLiteralMes(int mes)                                   {
            switch (mes) {
                case 1:
                    return "Janeiro";
                case 2:
                    return "Fevereiro";
                case 3:
                    return "Março";
                case 4:
                    return "Abril";
                case 5:
                    return "Maio";
                case 6:
                    return "Junho";
                case 7:
                    return "Julho";
                case 8:
                    return "Agosto";
                case 9:
                    return "Setembro";
                case 10:
                    return "Outubro";
                case 11:
                    return "Novembro";
                case 12:
                    return "Dezembro";
                default:
                    throw new ArgumentException("O mês informato é inválido, só são aceitos valores entre 1 e 12");
            }
        } 
    }
}

